package com.kzd.btgame.jetpack.api

import com.kzd.btgame.app.*
import com.kzd.btgame.entity.*
import com.kzd.btgame.utils.httpSign
import com.kzd.btgame.utils.key1
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.HttpResponseDataE
import com.module.lemlin.http.HttpResponseDataT
import rxhttp.RxHttp
import rxhttp.toClass


/**
 * 游戏评论点赞
 *
 * @param id 评论id
 * */
suspend fun personalDiscussGreat(id: String): DiscussGreatResponse =
    RxHttp.postForm(PERSONAL_PINGLUN_ZAN)
        .add("id", id)
        .toClass<DiscussGreatResponse>()
        .await()

/**
 * 发表评论
 * */
suspend fun personalAddDiscuss(
    id: String,
    content: String,
    reply_uid: String? = null,
    pid: String? = null,
    image: String? = null,
): HttpResponseData {
    val http = RxHttp.postForm(PERSONAL_ADD_PINGLUN)
        .add("id", id)
        .add("content", content)
    if (!reply_uid.isNullOrEmpty()) {
        http.add("reply_uid", reply_uid)
    }
    if (!pid.isNullOrEmpty()) {
        http.add("pid", pid)
    }
    if (!image.isNullOrEmpty()) {
        http.add("image", image)
    }
    return http.toClass<HttpResponseData>().await()
}

/**
 * 我的礼包
 * */
suspend fun personalMyGift(
    keyword: String? = null, page: String, limit: String,
): HttpResponseDataE<GameGift> = RxHttp.postForm(PERSONAL_MY_LB)
    .add("keyword", keyword)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<GameGift>>()
    .await()

/**
 * 游戏账号交易
 * */
suspend fun personalTrade(
    gameId: String? = null,
    keyword: String,
    sort: String,
    system: String,
    page: String,
    limit: String,
): HttpResponseDataE<GameBargain> {
    val http = RxHttp.postForm(PERSONAL_TRADE)
        .add("keyword", keyword)
        .add("sort", sort)
        .add("system", system)
        .add("p", page)
        .add("limit", limit)
    if (gameId != null) {
        http.add("game_id", gameId)
    }
    return http.toClass<HttpResponseDataE<GameBargain>>()
        .await()
}

/**
 * 账号交易-官方精选
 * */
suspend fun personalTradeChosen(): HttpResponseDataE<GameBargain> =
    RxHttp.postForm(PERSONAL_TRADE_JINGXUAN)
        .toClass<HttpResponseDataE<GameBargain>>()
        .await()

/**
 * 我玩過的遊戲
 * */
suspend fun personalMyGame(): HttpResponseDataE<GamePlayed> =
    RxHttp.postForm(PERSONAL_MY_YOUXI)
        .toClass<HttpResponseDataE<GamePlayed>>()
        .await()

/**
 * 小号选择
 * */
suspend fun personalGameSmallInfo(
    gameId: String, appid: String,
): HttpResponseDataE<GameSmall> = RxHttp.postForm(PERSONAL_GAME_SMALL_INFO)
    .add("game_id", gameId)
    .add("appid", appid)
    .toClass<HttpResponseDataE<GameSmall>>()
    .await()

/**
 * 小号交易
 * */
suspend fun personalTradeAdd(
    name: String,
    game_id: String,
    introduction: String,
    sname: String,
    small_id: String,
    two_passwd: String? = null,
    money: String,
    system: String,
    images: String,
): HttpResponseData = RxHttp.postForm(PERSONAL_TRADE_ADD)
    .addAll(httpSign(SPSConstance.uid, key = key1))
    .add("name", name)
    .add("game_id", game_id)
    .add("introduction", introduction)
    .add("sname", sname)
    .add("small_id", small_id)
    .add("two_passwd", two_passwd)
    .add("money", money)
    .add("system", system)
    .add("images", images)
    .toClass<HttpResponseData>()
    .await()

/**
 * 充值转游信息
 * */
suspend fun personalGetTurnInfo(game_id: String): HttpResponseDataT<TransferInfo> =
    RxHttp.postForm(PERSONAL_GET_TURN_INFO)
        .add("game_id", game_id)
        .toClass<HttpResponseDataT<TransferInfo>>()
        .await()

/**
 * 转游角色
 * */
suspend fun personalGetRoleList(
    appid: String, servers_id: String? = null,
): HttpResponseDataE<TransferRole> {
    val http = RxHttp.postForm(PERSONAL_GET_ROLE_LIST)
        .add("appid", appid)
    if (!servers_id.isNullOrEmpty()) {
        http.add("servers_id", servers_id)
    }
    return http.toClass<HttpResponseDataE<TransferRole>>().await()
}

/**
 * 充值转游提交申请
 * */
suspend fun personalSetTurn(
    gid: String,
    roleid: String,
    turn_gid: String,
    turn_roleid: String,
): HttpResponseData = RxHttp.postForm(PERSONAL_SET_TURN)
    .add("gid", gid)
    .add("roleid", roleid)
    .add("turn_gid", turn_gid)
    .add("turn_roleid", turn_roleid)
    .toClass<HttpResponseData>()
    .await()

/**
 * 签到数据
 * */
suspend fun personalGetSignInConfig(): HttpResponseDataT<MoneySign> =
    RxHttp.postForm(PERSONAL_GET_SIGN_IN_CONFIG)
        .toClass<HttpResponseDataT<MoneySign>>()
        .await()

/**
 * 签到
 * */
suspend fun personalSignIn(): HttpResponseData =
    RxHttp.postForm(PERSONAL_SIGN_IN)
        .toClass<HttpResponseData>()
        .await()

/**
 * 试玩任务
 * */
suspend fun personalTaskList(
    page: String, limit: String,
): HttpResponseDataE<MoneyTaskPlay> = RxHttp.postForm(PERSONAL_RENWU_LIST)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<MoneyTaskPlay>>()
    .await()

/**
 * 试玩报名、领取
 * */
suspend fun personalTaskChange(id: String): HttpResponseData =
    RxHttp.postForm(PERSONAL_RENWU_CHANGE)
        .add("id", id)
        .toClass<HttpResponseData>()
        .await()

/**
 * 积分记录
 * */
suspend fun personalGetMyOrder(
    type: Int, page: String, limit: String,
): HttpResponseDataE<MineOrder> = RxHttp.postForm(PERSONAL_GET_MY_ORDER)
    .add("type", type)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<MineOrder>>()
    .await()

/**
 * 游戏收藏列表
 * */
suspend fun personalGameCollect(
    page: String, limit: String,
): HttpResponseDataE<GameBean> = RxHttp.postForm(PERSONAL_YOUXI_SHOUCANG)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<GameBean>>()
    .await()

/**
 * 交易收藏列表
 * */
suspend fun personalTradeCollect(
    page: String, limit: String,
): HttpResponseDataE<GameBargain> = RxHttp.postForm(PERSONAL_JIAOYI_SHOUCANG)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<GameBargain>>()
    .await()

/**
 * 物品收藏列表
 * */
suspend fun personalGoodsCollect(
    page: String, limit: String,
): HttpResponseDataE<MallGoods> = RxHttp.postForm(PERSONAL_GOODS_SHOUCANG)
    .add("p", page)
    .add("limit", limit)
    .toClass<HttpResponseDataE<MallGoods>>()
    .await()

/**
 * 游戏抽奖数据
 * */
suspend fun personalLotteryData(): HttpResponseDataT<GameLottery> =
    RxHttp.postForm(PERSONAL_LOTTERY_DATA)
        .toClass<HttpResponseDataT<GameLottery>>()
        .await()

/**
 * 游戏抽奖
 * @param type 0抽1次，1抽10次
 * */
suspend fun personalLotteryObtain(type: String): HttpResponseDataE<LotteryObtain> =
    RxHttp.postForm(PERSONAL_LOTTERY_OBTAIN)
        .add("type", type)
        .toClass<HttpResponseDataE<LotteryObtain>>()
        .await()

/**
 * 游戏抽奖记录
 * */
suspend fun personalLotteryRecord(page: String, limit: String): HttpResponseDataE<LotteryRecord> =
    RxHttp.postForm(PERSONAL_LOTTERY_RECORD)
        .add("p", page)
        .add("limit", limit)
        .toClass<HttpResponseDataE<LotteryRecord>>()
        .await()